package com.yonyou.brigade.cron.user.ystrip;

import com.dangdang.ddframe.job.api.ShardingContext;
import com.dangdang.ddframe.job.api.simple.SimpleJob;
import com.yonyou.brigade.basic_init.model.BriChannel;
import com.yonyou.brigade.basic_init.service.IBriChannelService;
import com.yonyou.brigade.third_parties.ystrip.service.IYStripUserService;
import com.yonyou.ybzboot.starter.elasticjob.lite.annotation.ElasticJobConfig;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Component;

import java.util.List;

//@ElasticJobConfig(cron = "0 0 1 * * ?",shardingTotalCount = 1)
//@Component
public class SyncYStripUserJob implements SimpleJob {
    private static Logger logger = LoggerFactory.getLogger(SyncYStripUserJob.class);

    @Autowired
    @Qualifier("briChannelServiceImpl")
    private IBriChannelService briChannelService;

    @Autowired
    @Qualifier("YStripUserServiceImpl")
    private IYStripUserService iyStripUserService;

    @Override
    public void execute(ShardingContext shardingContext) {
        List<BriChannel> briChannels = briChannelService.getEnableChannelByChannel("ystrip");
        if(briChannels != null && briChannels.size() > 0){
            briChannels.forEach(briChannel -> {
                if (BriChannel.SYNCUSER == briChannel.getSyncUser()) {
                    String tenant = briChannel.getTenant();
                    String orgpk = briChannel.getOrgpk();
                    iyStripUserService.syncAllUserToYStrip(tenant,orgpk);
                }
            });
        }
    }
}
